<template>
  <van-icon
    :color="value ? '#ffa500' : '#777'"
    :name="value ? 'star' : 'star-o'"
    @click="onCollect"
  />
</template>

<script>
import { addCollect, removeCollect } from '@/api/articles'
export default {
  name: 'CollectArticle',
  components: {

  },
  props: {
    value: {
      type: Boolean,
      required: true
    },
    articleId: {
      type: [String, Number, Object],
      required: true
    }
  },
  data () {
    return {

    }
  },
  created () {

  },
  methods: {
    async onCollect () {
      if (this.value) {
        // 取消收藏
        await removeCollect(this.articleId)
      } else {
        // 收藏文章
        await addCollect(this.articleId)
      }
      this.$emit('input', !this.value)
    }
  }
}
</script>

<style lang="less" scoped>
</style>
